package com.sh15tech.mp.weixin.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Tool {

    private static Logger log = LogManager.getLogger(Tool.class);
    private static SimpleDateFormat cn_format = new SimpleDateFormat("yyyy年MM月dd日");
    private static ObjectMapper mapper = new ObjectMapper();

    public static boolean isEmpty(String str) {

        return !(str != null && !"".equals(str.trim()));
    }

    public static String date2cn(Date date) {
        return cn_format.format(date);
    }

    public static Object toObj(String json, Class<?> clazz) {
        if (isEmpty(json)) {
            return null;
        }
        try {
            return mapper.readValue(json, clazz);
        } catch (Exception e) {
            log.error("failed to trans json to obj", e);
        }
        return null;
    }
}
